package com.inforich.screenData.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.inforich.common.enums.ReportSourceEnum;
import com.inforich.projectManage.service.IProjectService;
import java.util.Arrays;
import cn.hutool.core.bean.BeanUtil;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestParam;
import com.inforich.common.annotation.Log;
import com.inforich.common.core.controller.BaseController;
import com.inforich.common.core.domain.AjaxResult;
import com.inforich.common.enums.BusinessType;
import com.inforich.screenData.domain.ReportProjectComTransport;
import com.inforich.screenData.service.IReportProjectComTransportService;
import com.inforich.common.utils.poi.ExcelUtil;

/**
 * 项目公司运输日汇总Controller
 *
 * @author hjm
 * @date 2022-10-27
 */
@RestController
@RequestMapping("/screenData/reportProjectComTransport")
public class ReportProjectComTransportController extends BaseController {

  @Autowired
  private IReportProjectComTransportService reportProjectComTransportService;
  @Autowired
  private IProjectService projectService;

  /**
   * 查询项目公司运输日汇总列表
   */
  @PreAuthorize("@ss.hasPermi('screenData:reportProjectComTransport:list')")
  @GetMapping("/list")
  public Page<ReportProjectComTransport> list(Page<ReportProjectComTransport> page,
      ReportProjectComTransport reportProjectComTransport) {
    Map<String, Object> map = beanToMap(reportProjectComTransport);
    reportProjectComTransportService.pageReportProjectComTransport(page, map);
    return page;
  }


  /**
   * 导出项目公司运输日汇总列表
   */
  @PreAuthorize("@ss.hasPermi('screenData:reportProjectComTransport:export')")
  @Log(title = "项目公司运输日汇总", businessType = BusinessType.EXPORT)
  @PostMapping("/export")
  public void export(HttpServletResponse response,
      ReportProjectComTransport reportProjectComTransport) {
    Map<String, Object> map = beanToMap(reportProjectComTransport);
    List<ReportProjectComTransport> list = reportProjectComTransportService.listReportProjectComTransport(
        map);
    ExcelUtil<ReportProjectComTransport> util = new ExcelUtil<ReportProjectComTransport>(
        ReportProjectComTransport.class);
    util.exportExcel(response, list, "项目公司运输日汇总数据");
  }

  /**
   * 获取项目公司运输日汇总详细信息
   */
  @PreAuthorize("@ss.hasPermi('screenData:reportProjectComTransport:query')")
  @GetMapping(value = "/{id}")
  public AjaxResult getInfo(@PathVariable("id") Long id) {
    return AjaxResult.success(reportProjectComTransportService.getById(id));
  }

  /**
   * 新增项目公司运输日汇总
   */
  @PreAuthorize("@ss.hasPermi('screenData:reportProjectComTransport:add')")
  @Log(title = "项目公司运输日汇总", businessType = BusinessType.INSERT)
  @PostMapping
  public AjaxResult add(
      @Validated @RequestBody ReportProjectComTransport reportProjectComTransport) {
    if (reportProjectComTransportService.checkConflict(reportProjectComTransport)) {
      return AjaxResult.error("数据重复");
    }
    reportProjectComTransport.setProjectName(
        projectService.getProjectName(reportProjectComTransport.getProjectId()));
    reportProjectComTransport.setSource(ReportSourceEnum.BACK.getDbData().intValue());
    return toAjax(reportProjectComTransportService.save(reportProjectComTransport));
  }

  /**
   * 修改项目公司运输日汇总
   */
  @PreAuthorize("@ss.hasPermi('screenData:reportProjectComTransport:edit')")
  @Log(title = "项目公司运输日汇总", businessType = BusinessType.UPDATE)
  @PutMapping
  public AjaxResult edit(
      @Validated @RequestBody ReportProjectComTransport reportProjectComTransport) {
    if (reportProjectComTransportService.checkConflict(reportProjectComTransport)) {
      return AjaxResult.error("数据重复");
    }
    reportProjectComTransport.setProjectName(
        projectService.getProjectName(reportProjectComTransport.getProjectId()));
    reportProjectComTransport.setSource(ReportSourceEnum.BACK.getDbData().intValue());
    return toAjax(reportProjectComTransportService.updateById(reportProjectComTransport));
  }

  /**
   * 删除项目公司运输日汇总
   */
  @PreAuthorize("@ss.hasPermi('screenData:reportProjectComTransport:remove')")
  @Log(title = "项目公司运输日汇总", businessType = BusinessType.DELETE)
  @DeleteMapping("/{ids}")
  public AjaxResult remove(@PathVariable Long[] ids) {
    return toAjax(reportProjectComTransportService.removeByIds(Arrays.asList(ids)));
  }
}
